//
//  TribeRangeCell.m
//  PigMarket
//
//  Created by mac on 2019/5/21.
//  Copyright © 2019 felix.pigmarket.oc. All rights reserved.
//

#import "TribeRangeCell.h"

#define kUnOpenColor [UIColor colorWithHexString:@"#999999"]
@interface TribeRangeCell ()
/**
 当前位置tips
 */
@property (nonatomic , strong) UILabel *currentAddTips;
/**
 addressTitle
 */
@property (nonatomic , strong) UILabel *addressTitle;
/**
 detailAddress
 */
@property (nonatomic , strong) UILabel *detailAddress;
/**
 未开通
 */
@property (nonatomic , strong) UILabel *unOpenTips;
/**
 line
 */
@property (nonatomic , strong) UIView *line;
@end
@implementation TribeRangeCell

+ (instancetype)cellWithTableView:(UITableView *)tableView {
    static NSString *identifierID = @"identifierID";
    TribeRangeCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierID];
    if (cell == nil) {
        cell = [[TribeRangeCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifierID];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}
#pragma mark - init method
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initView];
        [self initLayout];
    }
    return self;
}

- (void)initView {
    // 添加子控件
    [self.contentView addSubview:self.currentAddTips];
    [self.contentView addSubview:self.addressTitle];
    [self.contentView addSubview:self.detailAddress];
    [self.contentView addSubview:self.unOpenTips];
    [self.contentView addSubview:self.line];
}

- (void)initLayout {
    // 布局子控件
    [self.currentAddTips mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(8);
        make.top.mas_equalTo(12);
        make.height.mas_equalTo(20);
    }];
    [self.addressTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.currentAddTips.mas_right).offset(5);
        make.top.mas_equalTo(12);
        make.height.mas_equalTo(20);
    }];
    [self.detailAddress mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(self.addressTitle.mas_bottom).offset(6);
        make.height.mas_equalTo(18);
    }];
    [self.unOpenTips mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-15);
        make.centerY.mas_equalTo(self.addressTitle.mas_centerY);
        make.height.mas_equalTo(18);
    }];
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.bottom.mas_equalTo(0);
        make.height.mas_equalTo(1);
        make.right.mas_equalTo(0);
    }];
}

- (void)configCellWithSearchResultModel:(MapSearchResult *)model{
    self.addressTitle.text = model.name;
    self.detailAddress.text = model.detailAddress;
    if (model.isCurrentLoc) {
        self.currentAddTips.hidden = NO;
        self.currentAddTips.text = @"【当前位置】";

    } else {
        self.currentAddTips.hidden = YES;
        self.currentAddTips.text = @"";
    }
    
    if (model.isInside) {
        self.unOpenTips.hidden = YES;
        self.addressTitle.textColor = [UIColor colorWithHexString:@"#707070"];
        self.detailAddress.textColor = [UIColor colorWithHexString:@"#707070"];

    } else {
        self.unOpenTips.hidden = NO;
        self.addressTitle.textColor = kUnOpenColor;
        self.detailAddress.textColor = kUnOpenColor;
    }
}
- (void)configUserSearchCellWithSearchResultModel:(UserSearchAddressResult *)model{
    self.addressTitle.text = model.name;
    self.detailAddress.text = model.detailAddress;
    if (model.isCurrentLoc) {
        self.currentAddTips.hidden = NO;
        self.currentAddTips.text = @"【当前位置】";
        
    } else {
        self.currentAddTips.hidden = YES;
        self.currentAddTips.text = @"";
    }
    
    if (model.isInside) {
        self.unOpenTips.hidden = YES;
        self.addressTitle.textColor = [UIColor colorWithHexString:@"#707070"];
        self.detailAddress.textColor = [UIColor colorWithHexString:@"#707070"];
        
    } else {
        self.unOpenTips.hidden = NO;
        self.addressTitle.textColor = kUnOpenColor;
        self.detailAddress.textColor = kUnOpenColor;
    }
}
#pragma mark - getter and setter
- (UILabel *)currentAddTips {
    if (!_currentAddTips) {
        _currentAddTips = [[UILabel alloc] init];
        _currentAddTips.textColor = [UIColor primaryColor];
        _currentAddTips.font = [UIFont middleFont];
    }
    return _currentAddTips;
}
- (UILabel *)addressTitle {
    if (!_addressTitle) {
        _addressTitle = [[UILabel alloc] init];
        _addressTitle.textColor = [UIColor textBlackColor];
        _addressTitle.font = [UIFont middleFont];
    }
    return _addressTitle;
}
- (UILabel *)detailAddress {
    if (!_detailAddress) {
        _detailAddress = [[UILabel alloc] init];
        _detailAddress.textColor = [UIColor colorWithHexString:@"#707070"];
        _detailAddress.font = [UIFont smallFont];
    }
    return _detailAddress;
}
- (UILabel *)unOpenTips {
    if (!_unOpenTips) {
        _unOpenTips = [[UILabel alloc] init];
        _unOpenTips.textColor = kUnOpenColor;
        _unOpenTips.font = [UIFont smallFont];
        self.unOpenTips.text = @"此区域未开通";
    }
    return _unOpenTips;
}
- (UIView *)line {
    if (!_line) {
        _line = [[UIView alloc] init];
        _line.backgroundColor = [UIColor colorWithHexString:@"#000000" alpha:0.08];
    }
    return _line;
}
@end
